package com.imooc.sell.utils.pyhutils;

import com.imooc.sell.VO.pan.RemarkResult;
import com.imooc.sell.VO.pan.RemarkResult2;
import com.imooc.sell.dataobject.Remark;
import com.imooc.sell.service.impl.RemarkServiceImpl;
import lombok.Setter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

@Setter
public class RemarkResultUtils {
    public static final int REMARKCODE_SUCCESS = 1;          /*成功状态码*/
    public static final int REMARKCODE_ERROR = 0;            /*失败状态码*/
    public static final String REMARKMSG_SUCCESS = "成功";   /*成功状态信息*/
    public static final String REMARKMSG_ERROR = "失败";     /*失败状态信息*/
    /*日志打印*/
    public static final Logger logger = LoggerFactory.getLogger(RemarkServiceImpl.class);

    /**
     * 用于返回一个RemarkResult结果
     *
     * @param list 查询到的所有元素的列表
     * @return RemarkResult
     */
    public static RemarkResult success(List<Remark> list) {
        RemarkResult rr = new RemarkResult();
        rr.setMcode(REMARKCODE_SUCCESS);
        rr.setMsg(REMARKMSG_SUCCESS);
        rr.setRemarkList(list);
        return rr;
    }


    /**
     * 查询不到时构建一个list属性为null的RemarkResult,由于方法有重复代码所以加上注解抑制重复代码警告
     *
     * @return 返回结果包装类
     */
    @SuppressWarnings("all")
    public static RemarkResult error() {
        RemarkResult rr = new RemarkResult();
        rr.setMcode(REMARKCODE_ERROR);
        rr.setMsg(REMARKMSG_ERROR);
        rr.setRemarkList(null);
        return rr;
    }

    @SuppressWarnings("all")
    public static RemarkResult error(String msg) {
        RemarkResult rr = new RemarkResult();
        rr.setMcode(REMARKCODE_ERROR);
        rr.setMsg(msg);
        rr.setRemarkList(null);
        return rr;
    }


    /**
     * 添加和更新评论时的返回函数调用
     *
     * @return 返回当前对象
     */
    public static RemarkResult2 success2() {
        RemarkResult2 rr = new RemarkResult2();
        rr.setMcode(REMARKCODE_SUCCESS);
        rr.setMsg(REMARKMSG_SUCCESS);
        return rr;
    }

    /**
     * 添加或者更新出错时调用该函数返回
     *
     * @return RemarkResult2
     */
    public static RemarkResult2 error2(String msg) {
        RemarkResult2 rr = new RemarkResult2();
        rr.setMcode(REMARKCODE_ERROR);
        rr.setMsg(msg);
        return rr;
    }

    /**
     * 函数重载
     *
     * @return 返回结果包装类
     */
    @SuppressWarnings("unused")
    public static RemarkResult2 error2() {
        RemarkResult2 rr = new RemarkResult2();
        rr.setMcode(REMARKCODE_ERROR);
        rr.setMsg(REMARKMSG_ERROR);
        return rr;
    }
}
